<template>
	<view>
		<!-- 切换tab -->
		<view class="tab-wrap">
			<view class="tab-item" :class="[tabIndex == index - 1 ? 'tab-act':'']" v-for='(item,index) in tab' @tap='changeTab(index)'>{{item}}</view>
		</view>
		
		<block v-if="tabIndex == -1">
		<!-- 我的自提点 -->
		<view class="my_pickup">
			当前自提点
		</view>
		
		<!-- 当前自提点的信息 -->
		<view class="now_pickup" v-if="now_pickup != null && history_status == true">
			<view class="pickup_top">
				<view class="left">
					<view class="title">
						{{now_pickup.point_name}}
					</view>
					<view class="custom">
						<text class="name">{{now_pickup.contact_person}}</text>
						<text class="mobile">{{now_pickup.contact_number}}</text>
					</view>
				</view>
				<view class="right">
					<!-- <view class="btn">
						选择
					</view> -->
				</view>
			</view>
			<view class="pickup_bot">
				地址：{{now_pickup.point_address}}
			</view>
		</view>
		<view class="no_box" v-else>
			<image src="https://wanchuyun-img.oss-cn-beijing.aliyuncs.com/guomai/f9bede86ecf6777ae86c83afe8c3747d9693e80f.png" mode=""></image>
			<text>暂无自提点</text>
		</view>
		
		<!-- 历史自提点 -->
		<view class="my_pickup" style="margin-top: 20rpx;">
			历史自提点
		</view>
		
		
		<view class="now_pickup" v-for="(item,index) in history_pickup" :key="index" v-if="history_pickup.length > 0 && history_status == true">
			<view class="pickup_top">
				<view class="left">
					<view class="title">
						{{item.pointInfo.point_name}}
					</view>
					<view class="custom">
						<text class="name">{{item.pointInfo.contact_person}}</text>
						<text class="mobile">{{item.pointInfo.contact_number}}</text>
					</view>
				</view>
				<view class="right" @click="check_pickup(item.pointInfo)">
					<view class="btn">
						选择
					</view>
				</view>
			</view>
			<view class="pickup_bot">
				地址：{{item.pointInfo.point_address}}
			</view>
		</view>
		
		<view class="no_box" v-else>
			<image src="https://wanchuyun-img.oss-cn-beijing.aliyuncs.com/guomai/f9bede86ecf6777ae86c83afe8c3747d9693e80f.png" mode=""></image>
			<text>暂无历史自提点</text>
		</view>
		</block>
		
		<block v-else>
			<view class="" style="margin-top: 105rpx;">
				<view class="now_pickup" style="margin-top: 20rpx;" v-for="(item,index) in other_pickup" :key="index" v-if="other_pickup.length > 0">
					<view class="pickup_top">
						<view class="left">
							<view class="title">
								{{item.point_name}}
								<text class="juli">(距离{{item.distance}})</text>
							</view>
							<view class="custom">
								<text class="name">{{item.contact_person}}</text>
								<text class="mobile">{{item.contact_number}}</text>
							</view>
						</view>
						<view class="right" @click="check_pickup(item)">
							<view class="btn">
								选择
							</view>
						</view>
					</view>
					<view class="pickup_bot">
						地址：{{item.point_address}}
					</view>
				</view>
				
				<view class="no_box" v-if="other_pickup.length == 0">
					<image src="https://wanchuyun-img.oss-cn-beijing.aliyuncs.com/guomai/f9bede86ecf6777ae86c83afe8c3747d9693e80f.png" mode=""></image>
					<text>暂无其他自提点</text>
				</view>
			</view>
			
			
		</block>
		
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				tab:['我的自提点','其他自提点'],
				tabIndex: -1,
				latitude: '',
				longitude: '',
				other_pickup:'',
				now_pickup:'',
				history_pickup: '',
				history_status: false
			};
		},
		onShow() {
			this.getLocation()
			this.history_list()
		},
		methods:{
			// 选择自提点
			check_pickup( item ){
				uni.navigateBack({
					delta:1
				})
				uni.$emit('checkPickUp',item)
			},
			changeTab(index){
				this.tabIndex = Number(index - 1)
			},
			// 地图坐标
			getLocation() {
				let that = this
				uni.getLocation({
				    type: 'bd09ll',
				    success: function (res) {
						that.longitude = res.longitude
						that.latitude = res.latitude
						that.Point_list(res.longitude,res.latitude)
				    },
				    fail: function () {
				        console.log('获取位置信息失败');
				    }
				});
			},
			
			// 其他自提点列表
			Point_list(longitude,latitude){
				let that = this;
				app.globalRequest({
					api: app.getApi().user.getPoint,
					data: {
						latitude: latitude,
						longitude: longitude
					},
					method: 'get'
				}).then(res => {
					if (res.code == 0) {
						that.other_pickup = res.data
					}
				}).catch(err => {
				
				})
			},
			
			// 当前和历史自提点列表
			history_list(){
				let that = this;
				app.globalRequest({
					api: app.getApi().user.historyList,
					method: 'get'
				}).then(res => {
					if (res.code == 0) {
						that.history_status = true
						that.now_pickup = res.data.last_point
						that.history_pickup = res.data.history_list
					}
				}).catch(err => {
				
				})
			}
			
			
		}
	}
</script>

<style lang="scss">
	.tab-wrap{
		width:100%;
		height: 88rpx;
		background: $dis-con-color;
		position: fixed;
		left:0;
		top: 0;
		z-index:888;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding:0 40rpx;
		box-sizing: border-box;
		border-top: 1rpx solid $dis-bg-color;
		border-bottom: 1rpx solid $dis-bg-color;
		.tab-item{
			width: 50%;
			display: flex;
			justify-content: center;
			font-size: 29rpx;
		}
		.tab-act{
			position: relative;
			color:$dis-font-color;
			font-size: 30rpx;
			font-weight: bold;
			&:after{
				content: '';
				width: 46rpx;
				height: 4rpx;
				background: $dis-font-color;
				border-radius: 4rpx;
				position: absolute;
				left:0;
				right:0;
				margin:auto;
				bottom:-10rpx;
			}
		}
	}
	.my_pickup{
		margin-top: 80rpx;
		font-size: 29rpx;
		color: #a5a5a5;
		background-color: #fff;
		width: 100%;
		padding: 25rpx;
		box-sizing: border-box;
	}
	
	.now_pickup{
		margin-top: 20rpx;
		width: 100%;
		background-color: #fff;
		padding: 20rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		.pickup_top{
			display: flex;
			align-items: center;
			justify-content: space-between;
			.left{
				display: flex;
				flex-direction: column;
				.title{
					font-size: 30rpx;
					color: #000;
					font-weight: bold;
					.juli{
						color: #EC1818;
						font-size: 24rpx;
						font-weight: normal;
						margin-left: 20rpx;
					}
				}
			}
			.custom{
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				.mobile{
					margin-left: 20rpx;
				}
			}
			.right{
				.btn{
					padding: 10rpx 25rpx;
					box-sizing: border-box;
					border-radius: 15rpx;
					background-color: #EC1818;
					color: #fff;
				}
			}
		}
		.pickup_bot{
			margin-top: 20rpx;
		}
	}
	
	.no_box{
		width: 230rpx;
		height: 230rpx;
		margin: 20rpx auto 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		image{
			width: 100%;
			height: 90%;
		}
		text{
			color: #a5a5a5;
			font-size: 25rpx;
		}
	}
</style>
